package Easy二叉树深度;

import org.testng.annotations.Test;

public class Solution {
    public int maxDepth(TreeNode root) {
        if (root == null){
            return 0;
        }
        int[] max={0};
        Depth(root,max,0);
        return max[0];
    }
    public void Depth(TreeNode root,int[] max,int n) {
        if (root != null){
            n++;
            Depth(root.left,max,n);
            Depth(root.right,max,n);
        }
        else{
            if (max[0] < n){
                max[0] = n;
            }
        }
    }
    @Test
    public void test(){
        TreeNode tree = new TreeNode(1,new TreeNode(2,new TreeNode(3),new TreeNode(4)),new TreeNode(2,new TreeNode(4),new TreeNode(3)));
        System.out.println(maxDepth(tree));
    }
}
